<!--
 * @Author: your name
 * @Date: 2020-08-18 22:47:15
 * @LastEditTime: 2020-08-20 11:04:48
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \ryfront\src\modules\users\Add.vue
-->
<template>
    <div>
        <el-form ref="userform" :model="user" label-width="80px">
            <el-form-item label="用户名">
                <el-input size="small" v-model="user.userAccount"></el-input>
            </el-form-item>
            <el-form-item label="密码">
                <el-input type="password" size="small" v-model="user.userPassword"></el-input>
            </el-form-item>
            <el-form-item label="确认密码">
                <el-input type="password" size="small" v-model="confirmPassword"></el-input>
            </el-form-item>
            <el-form-item label="邮箱">
                <el-input  size="small" v-model="user.userEmail"></el-input>
            </el-form-item>
            <el-form-item label="联系方式">
                <el-input  size="small" v-model="user.userPhone"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button size="small" type="primary" @click="addUser" >创建</el-button>
                <el-button size="small" @click="cancel">取消</el-button>
            </el-form-item>    
        </el-form>
    </div>
</template>

<script>
import {userAdd} from '@/api/index'
export default {
    name:'user_add',
    data(){
        return {
            user:{
                userAccount: '',
                userEmail: '',
                userId: 0,
                userLastLoginTime: '',
                userPassword: '',
                userPhone: '',
                userStatus: '1',//状态
            },
            confirmPassword:'',//确认密码字段
        }
    },
    methods:{
        addUser(){
            //验证并有加载效果

            userAdd(this.user).then((result) => {
              if(result.status == 200){
                    //保存token 到 localStorage
                    this.$message({
                        message: '添加成功!',
                        type: 'success',
                        duration: 2000,
                    });
                    //关闭弹出框
                    this.$emit("closeDialog");
              }  
            })

        },
        cancel(){
            this.$emit("closeDialog");
        }
    }
}
</script>

<style scoped>

</style>